<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>珠峰架构师成长计划</title>
    <link rel="stylesheet" type="text/css" href="../static/css/main.css">
</head>
<body>
<div class="nav">
    <div class="logo">
        
            珠峰架构师成长计划
        
    </div>
<ul><li><a href="../index.html">0.Async</a></li><li><a href="../html/0.editor.html">0.editor</a></li><li><a href="../html/0.module.html">0.module</a></li><li><a href="../html/1.ES2015.html">1.ES2015</a></li><li><a href="../html/2.Promise.html">2.Promise</a></li><li><a href="../html/3.Node.html">3.Node</a></li><li><a href="../html/4.NodeInstall.html">4.NodeInstall</a></li><li><a href="../html/5.REPL.html">5.REPL</a></li><li><a href="../html/6.NodeCore.html">6.NodeCore</a></li><li><a href="../html/7.module&NPM.html">7.module&NPM</a></li><li><a href="../html/8.Encoding.html">8.Encoding</a></li><li><a href="../html/9.Buffer.html">9.Buffer</a></li><li class="active"><a href="../html/10.fs.html">10.fs</a></li><li><a href="../html/11.Stream-1.html">11.Stream-1</a></li><li><a href="../html/11.Stream-2.html">11.Stream-2</a></li><li><a href="../html/11.Stream-3.html">11.Stream-3</a></li><li><a href="../html/11.Stream-4.html">11.Stream-4</a></li><li><a href="../html/12-Network-2.html">12-Network-2</a></li><li><a href="../html/12.NetWork-3.html">12.NetWork-3</a></li><li><a href="../html/12.Network-1.html">12.Network-1</a></li><li><a href="../html/13.tcp.html">13.tcp</a></li><li><a href="../html/14.http-1.html">14.http-1</a></li><li><a href="../html/14.http-2.html">14.http-2</a></li><li><a href="../html/15.compress.html">15.compress</a></li><li><a href="../html/16.crypto.html">16.crypto</a></li><li><a href="../html/17.process.html">17.process</a></li><li><a href="../html/18.yargs.html">18.yargs</a></li><li><a href="../html/19.cache.html">19.cache</a></li><li><a href="../html/20.action.html">20.action</a></li><li><a href="../html/21.https.html">21.https</a></li><li><a href="../html/22.cookie.html">22.cookie</a></li><li><a href="../html/23.session.html">23.session</a></li><li><a href="../html/24.express-1.html">24.express-1</a></li><li><a href="../html/24.express-2.html">24.express-2</a></li><li><a href="../html/24.express-3.html">24.express-3</a></li><li><a href="../html/24.express-4.html">24.express-4</a></li><li><a href="../html/25.koa-1.html">25.koa-1</a></li><li><a href="../html/26.webpack-1-basic.html">26.webpack-1-basic</a></li><li><a href="../html/26.webpack-2-optimize.html">26.webpack-2-optimize</a></li><li><a href="../html/26.webpack-3.tapable.html">26.webpack-3.tapable</a></li><li><a href="../html/26.webpack-4-AST.html">26.webpack-4-AST</a></li><li><a href="../html/26.webpack-5-source.html">26.webpack-5-source</a></li><li><a href="../html/26.webpack-6-loader.html">26.webpack-6-loader</a></li><li><a href="../html/26.webpack-7-plugin.html">26.webpack-7-plugin</a></li><li><a href="../html/26.webpack-8-hand.html">26.webpack-8-hand</a></li><li><a href="../html/27.react-1.html">27.react-1</a></li><li><a href="../html/27.react-2.html">27.react-2</a></li><li><a href="../html/27.react-3.html">27.react-3</a></li><li><a href="../html/27.react-4-immutable.html">27.react-4-immutable</a></li><li><a href="../html/27.react-5-react-dom-diff.html">27.react-5-react-dom-diff</a></li><li><a href="../html/27.react-6.html">27.react-6</a></li><li><a href="../html/28.react-mobx.html">28.react-mobx</a></li><li><a href="../html/28.redux-0.html">28.redux-0</a></li><li><a href="../html/28.redux-1.html">28.redux-1</a></li><li><a href="../html/28.redux-2-中间件.html">28.redux-2-中间件</a></li><li><a href="../html/28.redux-3-saga.html">28.redux-3-saga</a></li><li><a href="../html/28.redux-jwt-back.html">28.redux-jwt-back</a></li><li><a href="../html/28.redux-jwt-front.html">28.redux-jwt-front</a></li><li><a href="../html/29.mongodb-1.html">29.mongodb-1</a></li><li><a href="../html/29.mongodb-2.html">29.mongodb-2</a></li><li><a href="../html/29.mongodb-3.html">29.mongodb-3</a></li><li><a href="../html/29.mongodb-4.html">29.mongodb-4</a></li><li><a href="../html/29.mongodb-5.html">29.mongodb-5</a></li><li><a href="../html/29.mongodb-6.html">29.mongodb-6</a></li><li><a href="../html/30.cms-1-mysql.html">30.cms-1-mysql</a></li><li><a href="../html/30.cms-2-mysql.html">30.cms-2-mysql</a></li><li><a href="../html/30.cms-3-mysql.html">30.cms-3-mysql</a></li><li><a href="../html/30.cms-4-egg.html">30.cms-4-egg</a></li><li><a href="../html/30.cms-5-api.html">30.cms-5-api</a></li><li><a href="../html/30.cms-6-roadhog.html">30.cms-6-roadhog</a></li><li><a href="../html/30.cms-7-umi.html">30.cms-7-umi</a></li><li><a href="../html/30.cms-8-dva.html">30.cms-8-dva</a></li><li><a href="../html/30.cms-9-dva.html">30.cms-9-dva</a></li><li><a href="../html/30.cms-10-front.html">30.cms-10-front</a></li><li><a href="../html/30.cms-11-deploy.html">30.cms-11-deploy</a></li><li><a href="../html/33.redis.html">33.redis</a></li><li><a href="../html/34.unittest.html">34.unittest</a></li><li><a href="../html/35.jwt.html">35.jwt</a></li><li><a href="../html/36.websocket-1.html">36.websocket-1</a></li><li><a href="../html/36.websocket-2.html">36.websocket-2</a></li><li><a href="../html/38.chat-api-1.html">38.chat-api-1</a></li><li><a href="../html/38.chat-api-2.html">38.chat-api-2</a></li><li><a href="../html/38.chat-3.html">38.chat-3</a></li><li><a href="../html/38.chat-api-3.html">38.chat-api-3</a></li><li><a href="../html/38.chat.html">38.chat</a></li><li><a href="../html/38.chat2.html">38.chat2</a></li><li><a href="../html/38.chat2.html">38.chat2</a></li><li><a href="../html/39.crawl-0.html">39.crawl-0</a></li><li><a href="../html/39.crawl-1.html">39.crawl-1</a></li><li><a href="../html/39.crawl-2.html">39.crawl-2</a></li><li><a href="../html/40.deploy.html">40.deploy</a></li><li><a href="../html/41.safe.html">41.safe</a></li><li><a href="../html/42.test.html">42.test</a></li><li><a href="../html/43.nginx.html">43.nginx</a></li><li><a href="../html/44.enzyme.html">44.enzyme</a></li><li><a href="../html/45.docker.html">45.docker</a></li><li><a href="../html/46.elastic.html">46.elastic</a></li><li><a href="../html/47.oauth.html">47.oauth</a></li><li><a href="../html/48.wxpay.html">48.wxpay</a></li><li><a href="../html/49.nunjucks.html">49.nunjucks</a></li><li><a href="../html/50.ketang.html">50.ketang</a></li><li><a href="../html/index.html">index</a></li><li><a href="../html/51.typescript.html">51.typescript</a></li><li><a href="../html/52.UML.html">52.UML</a></li><li><a href="../html/53.design.html">53.design</a></li><li><a href="../html/index.html">index</a></li><li><a href="../html/54.linux.html">54.linux</a></li><li><a href="../html/55.yaml.html">55.yaml</a></li><li><a href="../html/50.ketang2.html">50.ketang2</a></li><li><a href="../html/56.ts.html">56.ts</a></li><li><a href="../html/57.ts_react.html">57.ts_react</a></li><li><a href="../html/58.react-ssr.html">58.react-ssr</a></li><li><a href="../html/59.react-ssr.html">59.react-ssr</a></li></ul></div>


<div class="warpper">

    <div class="page-toc">
        <ul><li><a href="#t01. fs模块">1. fs模块</a></li><li><a href="#t12. 整体读取文件">2. 整体读取文件</a><ul><li><a href="#t22.1 异步读取">2.1 异步读取</a></li><li><a href="#t32.2 同步读取">2.2 同步读取</a></li></ul></li><li><a href="#t43. 写入文件">3. 写入文件</a><ul><li><a href="#t53.1 异步写入">3.1 异步写入</a></li><li><a href="#t63.2 同步写入">3.2 同步写入</a></li><li><a href="#t73.3 追加文件">3.3 追加文件</a></li><li><a href="#t83.4 拷贝文件">3.4 拷贝文件</a></li></ul></li><li><a href="#t94. 从指定位置处开始读取文件">4. 从指定位置处开始读取文件</a><ul><li><a href="#t104.1 打开文件">4.1 打开文件</a></li><li><a href="#t114.2 读取文件">4.2 读取文件</a></li><li><a href="#t124.3 写入文件">4.3 写入文件</a></li><li><a href="#t134.4 同步磁盘缓存">4.4 同步磁盘缓存</a></li><li><a href="#t144.5 关闭文件">4.5 关闭文件</a></li><li><a href="#t154.6 拷贝文件">4.6 拷贝文件</a></li></ul></li><li><a href="#t165 目录操作">5 目录操作</a><ul><li><a href="#t175.1 创建目录">5.1 创建目录</a></li><li><a href="#t185.2 判断一个文件是否有权限访问">5.2 判断一个文件是否有权限访问</a></li><li><a href="#t195.3 读取目录下所有的文件">5.3 读取目录下所有的文件</a></li><li><a href="#t205.4 查看文件目录信息">5.4 查看文件目录信息</a></li><li><a href="#t215.5 移动文件或目录">5.5 移动文件或目录</a></li><li><a href="#t225.6 删除文件">5.6 删除文件</a></li><li><a href="#t235.7 截断文件">5.7 截断文件</a></li><li><a href="#t245.8  监视文件或目录">5.8  监视文件或目录</a></li></ul></li><li><a href="#t256 递归创建目录">6 递归创建目录</a><ul><li><a href="#t266.1 同步创建目录">6.1 同步创建目录</a></li><li><a href="#t276.2 异步创建目录">6.2 异步创建目录</a></li><li><a href="#t286.3 Async+Await创建目录">6.3 Async+Await创建目录</a></li></ul></li><li><a href="#t297. 递归删除目录">7. 递归删除目录</a><ul><li><a href="#t307.1  同步删除目录(深度优先)">7.1  同步删除目录(深度优先)</a></li><li><a href="#t317.2 异步删除非空目录(Promise版)">7.2 异步删除非空目录(Promise版)</a></li><li><a href="#t327.3 异步串行删除目录(深度优先)">7.3 异步串行删除目录(深度优先)</a></li><li><a href="#t337.4 异步并行删除目录(深度优先)">7.4 异步并行删除目录(深度优先)</a></li><li><a href="#t347.5 同步删除目录(广度优先)">7.5 同步删除目录(广度优先)</a></li><li><a href="#t357.6 异步删除目录(广度优先)">7.6 异步删除目录(广度优先)</a></li></ul></li><li><a href="#t368.  遍历算法">8.  遍历算法</a><ul><li><a href="#t378.1 同步深度优先+先序遍历">8.1 同步深度优先+先序遍历</a></li><li><a href="#t388.2 异步深度优先+先序遍历">8.2 异步深度优先+先序遍历</a></li><li><a href="#t398.3 同步广度优先+先序遍历">8.3 同步广度优先+先序遍历</a></li><li><a href="#t408.4 异步广度优先+先序遍历">8.4 异步广度优先+先序遍历</a></li></ul></li><li><a href="#t418. path模块">8. path模块</a></li><li><a href="#t429. flags">9. flags</a></li><li><a href="#t4310. 助记">10. 助记</a></li><li><a href="#t4411. linux权限">11. linux权限</a></li></ul>
    </div>
    
    <div class="content markdown-body">
        <h2 id="t01. fs&#x6A21;&#x5757;">1. fs&#x6A21;&#x5757; <a href="#t01. fs&#x6A21;&#x5757;"> # </a></h2>
<ul>
<li>&#x5728;Node.js&#x4E2D;&#xFF0C;&#x4F7F;&#x7528;fs&#x6A21;&#x5757;&#x6765;&#x5B9E;&#x73B0;&#x6240;&#x6709;&#x6709;&#x5173;&#x6587;&#x4EF6;&#x53CA;&#x76EE;&#x5F55;&#x7684;&#x521B;&#x5EFA;&#x3001;&#x5199;&#x5165;&#x53CA;&#x5220;&#x9664;&#x64CD;&#x4F5C;&#x3002;</li>
<li>&#x5728;fs&#x6A21;&#x5757;&#x4E2D;&#xFF0C;&#x6240;&#x6709;&#x7684;&#x65B9;&#x6CD5;&#x90FD;&#x5206;&#x4E3A;&#x540C;&#x6B65;&#x548C;&#x5F02;&#x6B65;&#x4E24;&#x79CD;&#x5B9E;&#x73B0;&#x3002;</li>
<li>&#x5177;&#x6709;<code>sync</code>&#x540E;&#x7F00;&#x7684;&#x65B9;&#x6CD5;&#x4E3A;&#x540C;&#x6B65;&#x65B9;&#x6CD5;&#xFF0C;&#x4E0D;&#x5177;&#x6709;<code>sync</code>&#x540E;&#x7F00;&#x7684;&#x65B9;&#x6CD5;&#x4E3A;&#x5F02;&#x6B65;&#x65B9;&#x6CD5;&#x3002;</li>
</ul>
<h2 id="t12. &#x6574;&#x4F53;&#x8BFB;&#x53D6;&#x6587;&#x4EF6;">2. &#x6574;&#x4F53;&#x8BFB;&#x53D6;&#x6587;&#x4EF6; <a href="#t12. &#x6574;&#x4F53;&#x8BFB;&#x53D6;&#x6587;&#x4EF6;"> # </a></h2>
<h3 id="t22.1 &#x5F02;&#x6B65;&#x8BFB;&#x53D6;">2.1 &#x5F02;&#x6B65;&#x8BFB;&#x53D6; <a href="#t22.1 &#x5F02;&#x6B65;&#x8BFB;&#x53D6;"> # </a></h3>
<pre><code class="lang-js">fs.readFile(path[, options], callback)
</code></pre>
<ul>
<li>options<ul>
<li>encoding</li>
<li>flag flag <string> &#x9ED8;&#x8BA4; = &apos;r&apos;</string></li>
</ul>
</li>
</ul>
<h3 id="t32.2 &#x540C;&#x6B65;&#x8BFB;&#x53D6;">2.2 &#x540C;&#x6B65;&#x8BFB;&#x53D6; <a href="#t32.2 &#x540C;&#x6B65;&#x8BFB;&#x53D6;"> # </a></h3>
<pre><code class="lang-js">fs.readFileSync(path[, options])
</code></pre>
<h2 id="t43. &#x5199;&#x5165;&#x6587;&#x4EF6;">3. &#x5199;&#x5165;&#x6587;&#x4EF6; <a href="#t43. &#x5199;&#x5165;&#x6587;&#x4EF6;"> # </a></h2>
<h3 id="t53.1 &#x5F02;&#x6B65;&#x5199;&#x5165;">3.1 &#x5F02;&#x6B65;&#x5199;&#x5165; <a href="#t53.1 &#x5F02;&#x6B65;&#x5199;&#x5165;"> # </a></h3>
<pre><code class="lang-js">fs.writeFile(file, data[, options], callback)
</code></pre>
<ul>
<li>options<ul>
<li>encoding</li>
<li>flag flag <string> &#x9ED8;&#x8BA4; = &apos;w&apos;</string></li>
<li>mode &#x8BFB;&#x5199;&#x6743;&#x9650;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;0666</li>
</ul>
</li>
</ul>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> fs = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;fs&apos;</span>);
fs.writeFile(<span class="hljs-string">&apos;./1.txt&apos;</span>,<span class="hljs-built_in">Date</span>.now()+<span class="hljs-string">&apos;\n&apos;</span>,{<span class="hljs-attr">flag</span>:<span class="hljs-string">&apos;a&apos;</span>},<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;ok&apos;</span>);
});
</code></pre>
<h3 id="t63.2 &#x540C;&#x6B65;&#x5199;&#x5165;">3.2 &#x540C;&#x6B65;&#x5199;&#x5165; <a href="#t63.2 &#x540C;&#x6B65;&#x5199;&#x5165;"> # </a></h3>
<pre><code class="lang-js">fs.writeFileSync(file, data[, options])
</code></pre>
<h3 id="t73.3 &#x8FFD;&#x52A0;&#x6587;&#x4EF6;">3.3 &#x8FFD;&#x52A0;&#x6587;&#x4EF6; <a href="#t73.3 &#x8FFD;&#x52A0;&#x6587;&#x4EF6;"> # </a></h3>
<blockquote>
<p>fs.appendFile(file, data[, options], callback)</p>
</blockquote>
<pre><code class="lang-js">fs.appendFile(<span class="hljs-string">&apos;./1.txt&apos;</span>,<span class="hljs-built_in">Date</span>.now()+<span class="hljs-string">&apos;\n&apos;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;ok&apos;</span>);
})
</code></pre>
<h3 id="t83.4 &#x62F7;&#x8D1D;&#x6587;&#x4EF6;">3.4 &#x62F7;&#x8D1D;&#x6587;&#x4EF6; <a href="#t83.4 &#x62F7;&#x8D1D;&#x6587;&#x4EF6;"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">copy</span>(<span class="hljs-params">src,target</span>)</span>{
  fs.readFile(src,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">err,data</span>)</span>{
    fs.writeFile(target,data);
  })
}
</code></pre>
<h2 id="t94. &#x4ECE;&#x6307;&#x5B9A;&#x4F4D;&#x7F6E;&#x5904;&#x5F00;&#x59CB;&#x8BFB;&#x53D6;&#x6587;&#x4EF6;">4. &#x4ECE;&#x6307;&#x5B9A;&#x4F4D;&#x7F6E;&#x5904;&#x5F00;&#x59CB;&#x8BFB;&#x53D6;&#x6587;&#x4EF6; <a href="#t94. &#x4ECE;&#x6307;&#x5B9A;&#x4F4D;&#x7F6E;&#x5904;&#x5F00;&#x59CB;&#x8BFB;&#x53D6;&#x6587;&#x4EF6;"> # </a></h2>
<h3 id="t104.1 &#x6253;&#x5F00;&#x6587;&#x4EF6;">4.1 &#x6253;&#x5F00;&#x6587;&#x4EF6; <a href="#t104.1 &#x6253;&#x5F00;&#x6587;&#x4EF6;"> # </a></h3>
<blockquote>
<p>fs.open(filename,flags,[mode],callback);</p>
<ul>
<li>FileDescriptor &#x662F;&#x6587;&#x4EF6;&#x63CF;&#x8FF0;&#x7B26;</li>
<li>FileDescriptor &#x53EF;&#x4EE5;&#x88AB;&#x7528;&#x6765;&#x8868;&#x793A;&#x6587;&#x4EF6;</li>
<li>in  -- &#x6807;&#x51C6;&#x8F93;&#x5165;(&#x952E;&#x76D8;)&#x7684;&#x63CF;&#x8FF0;&#x7B26;</li>
<li>out -- &#x6807;&#x51C6;&#x8F93;&#x51FA;(&#x5C4F;&#x5E55;)&#x7684;&#x63CF;&#x8FF0;&#x7B26;</li>
<li>err -- &#x6807;&#x51C6;&#x9519;&#x8BEF;&#x8F93;&#x51FA;(&#x5C4F;&#x5E55;)&#x7684;&#x63CF;&#x8FF0;&#x7B26;</li>
</ul>
</blockquote>
<pre><code class="lang-js">fs.open(<span class="hljs-string">&apos;./1,txt&apos;</span>,<span class="hljs-string">&apos;r&apos;</span>,<span class="hljs-number">0600</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">err,fd</span>)</span>{});
</code></pre>
<h3 id="t114.2 &#x8BFB;&#x53D6;&#x6587;&#x4EF6;">4.2 &#x8BFB;&#x53D6;&#x6587;&#x4EF6; <a href="#t114.2 &#x8BFB;&#x53D6;&#x6587;&#x4EF6;"> # </a></h3>
<blockquote>
<p>fs.read(fd, buffer, offset, length, position, callback((err, bytesRead, buffer)))</p>
</blockquote>
<pre><code class="lang-js"><span class="hljs-comment">//&#x73E0;&#x5CF0;&#x57F9;&#x8BAD;</span>
<span class="hljs-keyword">const</span> fs=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;fs&apos;</span>);
<span class="hljs-keyword">const</span> path=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;path&apos;</span>);
fs.open(path.join(__dirname,<span class="hljs-string">&apos;1.txt&apos;</span>),<span class="hljs-string">&apos;r&apos;</span>,<span class="hljs-number">0o666</span>,<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">err,fd</span>) </span>{
    <span class="hljs-built_in">console</span>.log(err);
    <span class="hljs-keyword">let</span> buf = Buffer.alloc(<span class="hljs-number">6</span>);
     fs.read(fd,buf,<span class="hljs-number">0</span>,<span class="hljs-number">6</span>,<span class="hljs-number">3</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">err, bytesRead, buffer</span>)</span>{
       <span class="hljs-built_in">console</span>.log(bytesRead);<span class="hljs-comment">//6</span>
       <span class="hljs-built_in">console</span>.log(buffer===buf);<span class="hljs-comment">//true</span>
       <span class="hljs-built_in">console</span>.log(buf.toString());<span class="hljs-comment">//&#x5CF0;&#x57F9;</span>
     })
})
</code></pre>
<h3 id="t124.3 &#x5199;&#x5165;&#x6587;&#x4EF6;">4.3 &#x5199;&#x5165;&#x6587;&#x4EF6; <a href="#t124.3 &#x5199;&#x5165;&#x6587;&#x4EF6;"> # </a></h3>
<blockquote>
<p>fs.write(fd, buffer[, offset[, length[, position]]], callback)</p>
</blockquote>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> fs=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;fs&apos;</span>);
<span class="hljs-keyword">const</span> path=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;path&apos;</span>);
fs.open(path.join(__dirname,<span class="hljs-string">&apos;1.txt&apos;</span>),<span class="hljs-string">&apos;w&apos;</span>,<span class="hljs-number">0o666</span>,<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">err,fd</span>) </span>{
    <span class="hljs-built_in">console</span>.log(err);
    <span class="hljs-keyword">let</span> buf=Buffer.from(<span class="hljs-string">&apos;&#x73E0;&#x5CF0;&#x57F9;&#x8BAD;&apos;</span>);
     fs.write(fd,buf,<span class="hljs-number">3</span>,<span class="hljs-number">6</span>,<span class="hljs-number">0</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">err, bytesWritten, buffer</span>)</span>{
       <span class="hljs-built_in">console</span>.log(bytesWritten);<span class="hljs-comment">//6</span>
       <span class="hljs-built_in">console</span>.log(buffer===buf);<span class="hljs-comment">//true</span>
       <span class="hljs-built_in">console</span>.log(buf.toString());<span class="hljs-comment">//&#x73E0;&#x5CF0;&#x57F9;&#x8BAD;</span>
     })
})
</code></pre>
<h3 id="t134.4 &#x540C;&#x6B65;&#x78C1;&#x76D8;&#x7F13;&#x5B58;">4.4 &#x540C;&#x6B65;&#x78C1;&#x76D8;&#x7F13;&#x5B58; <a href="#t134.4 &#x540C;&#x6B65;&#x78C1;&#x76D8;&#x7F13;&#x5B58;"> # </a></h3>
<blockquote>
<p>fs.fsync(fd,[callback]);</p>
</blockquote>
<h3 id="t144.5 &#x5173;&#x95ED;&#x6587;&#x4EF6;">4.5 &#x5173;&#x95ED;&#x6587;&#x4EF6; <a href="#t144.5 &#x5173;&#x95ED;&#x6587;&#x4EF6;"> # </a></h3>
<blockquote>
<p>fs.close(fd,[callback]);</p>
</blockquote>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> buf = Buffer.from(<span class="hljs-string">&apos;&#x73E0;&#x5CF0;&#x57F9;&#x8BAD;&apos;</span>);
fs.open(<span class="hljs-string">&apos;./2.txt&apos;</span>, <span class="hljs-string">&apos;w&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">err, fd</span>) </span>{
  fs.write(fd, buf, <span class="hljs-number">3</span>, <span class="hljs-number">6</span>, <span class="hljs-number">0</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">err, written, buffer</span>) </span>{
    <span class="hljs-built_in">console</span>.log(written);
    fs.fsync(fd, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">err</span>) </span>{
      fs.close(fd, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">err</span>) </span>{
          <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;&#x5199;&#x5165;&#x5B8C;&#x6BD5;!&apos;</span>)
        }
      );
    });
  })
});
</code></pre>
<h3 id="t154.6 &#x62F7;&#x8D1D;&#x6587;&#x4EF6;">4.6 &#x62F7;&#x8D1D;&#x6587;&#x4EF6; <a href="#t154.6 &#x62F7;&#x8D1D;&#x6587;&#x4EF6;"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> BUFFER_SIZE=<span class="hljs-number">1</span>;
<span class="hljs-keyword">const</span> path=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;path&apos;</span>);
<span class="hljs-keyword">const</span> fs=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;fs&apos;</span>);
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">copy</span>(<span class="hljs-params">src,dest,callback</span>) </span>{
    <span class="hljs-keyword">let</span> buf=Buffer.alloc(BUFFER_SIZE);
    fs.open(src,<span class="hljs-string">&apos;r&apos;</span>,(err,readFd)=&gt;{
        fs.open(dest,<span class="hljs-string">&apos;w&apos;</span>,(err,writeFd) =&gt; {
            !<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">read</span>(<span class="hljs-params"></span>) </span>{
                fs.read(readFd,buf,<span class="hljs-number">0</span>,BUFFER_SIZE,<span class="hljs-literal">null</span>,(err,bytesRead) =&gt; {
                    bytesRead&amp;&amp;fs.write(writeFd,buf,<span class="hljs-number">0</span>,bytesRead,read);
                });
            }()
        })
    });
}
copy(path.join(__dirname,<span class="hljs-string">&apos;1.txt&apos;</span>),path.join(__dirname,<span class="hljs-string">&apos;2.txt&apos;</span>),()=&gt;<span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;ok&apos;</span>));
</code></pre>
<h2 id="t165 &#x76EE;&#x5F55;&#x64CD;&#x4F5C;">5 &#x76EE;&#x5F55;&#x64CD;&#x4F5C; <a href="#t165 &#x76EE;&#x5F55;&#x64CD;&#x4F5C;"> # </a></h2>
<h3 id="t175.1 &#x521B;&#x5EFA;&#x76EE;&#x5F55;">5.1 &#x521B;&#x5EFA;&#x76EE;&#x5F55; <a href="#t175.1 &#x521B;&#x5EFA;&#x76EE;&#x5F55;"> # </a></h3>
<blockquote>
<p>fs.mkdir(path[, mode], callback)</p>
</blockquote>
<blockquote>
<p>&#x8981;&#x6C42;&#x7236;&#x76EE;&#x5F55;&#x5FC5;&#x987B;&#x5B58;&#x5728;</p>
</blockquote>
<h3 id="t185.2 &#x5224;&#x65AD;&#x4E00;&#x4E2A;&#x6587;&#x4EF6;&#x662F;&#x5426;&#x6709;&#x6743;&#x9650;&#x8BBF;&#x95EE;">5.2 &#x5224;&#x65AD;&#x4E00;&#x4E2A;&#x6587;&#x4EF6;&#x662F;&#x5426;&#x6709;&#x6743;&#x9650;&#x8BBF;&#x95EE; <a href="#t185.2 &#x5224;&#x65AD;&#x4E00;&#x4E2A;&#x6587;&#x4EF6;&#x662F;&#x5426;&#x6709;&#x6743;&#x9650;&#x8BBF;&#x95EE;"> # </a></h3>
<blockquote>
<p>fs.access(path[, mode], callback)</p>
<pre><code class="lang-js">fs.access(<span class="hljs-string">&apos;/etc/passwd&apos;</span>, fs.constants.R_OK | fs.constants.W_OK, (err) =&gt; {
  <span class="hljs-built_in">console</span>.log(err ? <span class="hljs-string">&apos;no access!&apos;</span> : <span class="hljs-string">&apos;can read/write&apos;</span>);
});
</code></pre>
</blockquote>
<h3 id="t195.3 &#x8BFB;&#x53D6;&#x76EE;&#x5F55;&#x4E0B;&#x6240;&#x6709;&#x7684;&#x6587;&#x4EF6;">5.3 &#x8BFB;&#x53D6;&#x76EE;&#x5F55;&#x4E0B;&#x6240;&#x6709;&#x7684;&#x6587;&#x4EF6; <a href="#t195.3 &#x8BFB;&#x53D6;&#x76EE;&#x5F55;&#x4E0B;&#x6240;&#x6709;&#x7684;&#x6587;&#x4EF6;"> # </a></h3>
<blockquote>
<p>fs.readdir(path[, options], callback)</p>
</blockquote>
<h3 id="t205.4 &#x67E5;&#x770B;&#x6587;&#x4EF6;&#x76EE;&#x5F55;&#x4FE1;&#x606F;">5.4 &#x67E5;&#x770B;&#x6587;&#x4EF6;&#x76EE;&#x5F55;&#x4FE1;&#x606F; <a href="#t205.4 &#x67E5;&#x770B;&#x6587;&#x4EF6;&#x76EE;&#x5F55;&#x4FE1;&#x606F;"> # </a></h3>
<blockquote>
<p>fs.stat(path, callback)</p>
</blockquote>
<ul>
<li>stats.isFile()</li>
<li>stats.isDirectory()</li>
<li>atime(Access Time)&#x4E0A;&#x6B21;&#x88AB;&#x8BFB;&#x53D6;&#x7684;&#x65F6;&#x95F4;&#x3002;</li>
<li>ctime(State Change Time)&#xFF1A;&#x5C5E;&#x6027;&#x6216;&#x5185;&#x5BB9;&#x4E0A;&#x6B21;&#x88AB;&#x4FEE;&#x6539;&#x7684;&#x65F6;&#x95F4;&#x3002;</li>
<li>mtime(Modified time)&#xFF1A;&#x6863;&#x6848;&#x7684;&#x5185;&#x5BB9;&#x4E0A;&#x6B21;&#x88AB;&#x4FEE;&#x6539;&#x7684;&#x65F6;&#x95F4;&#x3002;</li>
</ul>
<h3 id="t215.5 &#x79FB;&#x52A8;&#x6587;&#x4EF6;&#x6216;&#x76EE;&#x5F55;">5.5 &#x79FB;&#x52A8;&#x6587;&#x4EF6;&#x6216;&#x76EE;&#x5F55; <a href="#t215.5 &#x79FB;&#x52A8;&#x6587;&#x4EF6;&#x6216;&#x76EE;&#x5F55;"> # </a></h3>
<pre><code class="lang-js">fs.rename(oldPath, newPath, callback)
</code></pre>
<h3 id="t225.6 &#x5220;&#x9664;&#x6587;&#x4EF6;">5.6 &#x5220;&#x9664;&#x6587;&#x4EF6; <a href="#t225.6 &#x5220;&#x9664;&#x6587;&#x4EF6;"> # </a></h3>
<pre><code class="lang-js">fs.unlink(path, callback)
</code></pre>
<h3 id="t235.7 &#x622A;&#x65AD;&#x6587;&#x4EF6;">5.7 &#x622A;&#x65AD;&#x6587;&#x4EF6; <a href="#t235.7 &#x622A;&#x65AD;&#x6587;&#x4EF6;"> # </a></h3>
<pre><code class="lang-js">fs.ftruncate(fd[, len], callback)
</code></pre>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> fd = fs.openSync(<span class="hljs-string">&apos;temp.txt&apos;</span>, <span class="hljs-string">&apos;r+&apos;</span>);
<span class="hljs-comment">// &#x622A;&#x65AD;&#x6587;&#x4EF6;&#x81F3;&#x524D;4&#x4E2A;&#x5B57;&#x8282;</span>
fs.ftruncate(fd, <span class="hljs-number">4</span>, (err) =&gt; {
  <span class="hljs-built_in">console</span>.log(fs.readFileSync(<span class="hljs-string">&apos;temp.txt&apos;</span>, <span class="hljs-string">&apos;utf8&apos;</span>));
});
</code></pre>
<h3 id="t245.8  &#x76D1;&#x89C6;&#x6587;&#x4EF6;&#x6216;&#x76EE;&#x5F55;">5.8  &#x76D1;&#x89C6;&#x6587;&#x4EF6;&#x6216;&#x76EE;&#x5F55; <a href="#t245.8  &#x76D1;&#x89C6;&#x6587;&#x4EF6;&#x6216;&#x76EE;&#x5F55;"> # </a></h3>
<pre><code class="lang-js">fs.watchFile(filename[, options], listener)
</code></pre>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> fs = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;fs&apos;</span>);
fs.watchFile(<span class="hljs-string">&apos;1.txt&apos;</span>, (curr, prev) =&gt; {
  <span class="hljs-comment">//parse() &#x65B9;&#x6CD5;&#x53EF;&#x89E3;&#x6790;&#x4E00;&#x4E2A;&#x65E5;&#x671F;&#x65F6;&#x95F4;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x5E76;&#x8FD4;&#x56DE; 1970/1/1 &#x5348;&#x591C;&#x8DDD;&#x79BB;&#x8BE5;&#x65E5;&#x671F;&#x65F6;&#x95F4;&#x7684;&#x6BEB;&#x79D2;&#x6570;&#x3002;</span>
  <span class="hljs-keyword">if</span>(<span class="hljs-built_in">Date</span>.parse(prev.ctime)==<span class="hljs-number">0</span>){
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;&#x521B;&#x5EFA;&apos;</span>);
  }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(<span class="hljs-built_in">Date</span>.parse(curr.ctime)==<span class="hljs-number">0</span>){
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;&#x5220;&#x9664;&apos;</span>);
  }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(<span class="hljs-built_in">Date</span>.parse(prev.ctime) != <span class="hljs-built_in">Date</span>.parse(curr.ctime)){
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;&#x4FEE;&#x6539;&apos;</span>);
  }
});

</code></pre>
<h2 id="t256 &#x9012;&#x5F52;&#x521B;&#x5EFA;&#x76EE;&#x5F55;">6 &#x9012;&#x5F52;&#x521B;&#x5EFA;&#x76EE;&#x5F55; <a href="#t256 &#x9012;&#x5F52;&#x521B;&#x5EFA;&#x76EE;&#x5F55;"> # </a></h2>
<h3 id="t266.1 &#x540C;&#x6B65;&#x521B;&#x5EFA;&#x76EE;&#x5F55;">6.1 &#x540C;&#x6B65;&#x521B;&#x5EFA;&#x76EE;&#x5F55; <a href="#t266.1 &#x540C;&#x6B65;&#x521B;&#x5EFA;&#x76EE;&#x5F55;"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> fs=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;fs&apos;</span>);
<span class="hljs-keyword">let</span> path=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;path&apos;</span>);
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">makepSync</span>(<span class="hljs-params">dir</span>) </span>{
    <span class="hljs-keyword">let</span> parts=dir.split(path.sep);
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i=<span class="hljs-number">1</span>;i&lt;=parts.length;i++){
        <span class="hljs-keyword">let</span> parent=parts.slice(<span class="hljs-number">0</span>,i).join(path.sep);
        <span class="hljs-keyword">try</span> {
            fs.accessSync(parent);
        } <span class="hljs-keyword">catch</span> (error) {
            fs.mkdirSync(parent);
        }

    }
}
</code></pre>
<h3 id="t276.2 &#x5F02;&#x6B65;&#x521B;&#x5EFA;&#x76EE;&#x5F55;">6.2 &#x5F02;&#x6B65;&#x521B;&#x5EFA;&#x76EE;&#x5F55; <a href="#t276.2 &#x5F02;&#x6B65;&#x521B;&#x5EFA;&#x76EE;&#x5F55;"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">makepAsync</span>(<span class="hljs-params">dir,callback</span>) </span>{
    <span class="hljs-keyword">let</span> parts=dir.split(path.sep);
    <span class="hljs-keyword">let</span> i=<span class="hljs-number">1</span>;
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">next</span>(<span class="hljs-params"></span>) </span>{
        <span class="hljs-keyword">if</span> (i&gt;parts.length)
            <span class="hljs-keyword">return</span> callback&amp;&amp;callback();    
        <span class="hljs-keyword">let</span> parent=parts.slice(<span class="hljs-number">0</span>,i++).join(path.sep);
        fs.access(parent,err =&gt; {
            <span class="hljs-keyword">if</span> (err) {
                fs.mkdir(parent,next);
            } <span class="hljs-keyword">else</span> {
                next();
            }
        });
    }
    next();
}
</code></pre>
<h3 id="t286.3 Async+Await&#x521B;&#x5EFA;&#x76EE;&#x5F55;">6.3 Async+Await&#x521B;&#x5EFA;&#x76EE;&#x5F55; <a href="#t286.3 Async+Await&#x521B;&#x5EFA;&#x76EE;&#x5F55;"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">mkdir</span>(<span class="hljs-params">parent</span>) </span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function">(<span class="hljs-params">resolve,reject</span>) =&gt;</span> {
        fs.mkdir(parent,err =&gt; {
            <span class="hljs-keyword">if</span> (err) reject(err);
            <span class="hljs-keyword">else</span> resolve();
        });
    });
}

<span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">access</span>(<span class="hljs-params">parent</span>) </span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function">(<span class="hljs-params">resolve,reject</span>) =&gt;</span> {
        fs.access(parent,err =&gt; {
            <span class="hljs-keyword">if</span> (err) reject(err);
            <span class="hljs-keyword">else</span> resolve();
        });
    });
}
<span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">makepPromise</span>(<span class="hljs-params">dir,callback</span>) </span>{
    <span class="hljs-keyword">let</span> parts=dir.split(path.sep);
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i=<span class="hljs-number">1</span>;i&lt;=parts.length;i++){
        <span class="hljs-keyword">let</span> parent=parts.slice(<span class="hljs-number">0</span>,i).join(path.sep);
        <span class="hljs-keyword">try</span> {
            <span class="hljs-keyword">await</span> access(parent);
        }<span class="hljs-keyword">catch</span>(err) {
            <span class="hljs-keyword">await</span> mkdir(parent);
        }

    }
}
</code></pre>
<h2 id="t297. &#x9012;&#x5F52;&#x5220;&#x9664;&#x76EE;&#x5F55;">7. &#x9012;&#x5F52;&#x5220;&#x9664;&#x76EE;&#x5F55; <a href="#t297. &#x9012;&#x5F52;&#x5220;&#x9664;&#x76EE;&#x5F55;"> # </a></h2>
<h3 id="t307.1  &#x540C;&#x6B65;&#x5220;&#x9664;&#x76EE;&#x5F55;(&#x6DF1;&#x5EA6;&#x4F18;&#x5148;)">7.1  &#x540C;&#x6B65;&#x5220;&#x9664;&#x76EE;&#x5F55;(&#x6DF1;&#x5EA6;&#x4F18;&#x5148;) <a href="#t307.1  &#x540C;&#x6B65;&#x5220;&#x9664;&#x76EE;&#x5F55;(&#x6DF1;&#x5EA6;&#x4F18;&#x5148;)"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> fs=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;fs&apos;</span>);
<span class="hljs-keyword">let</span> path=<span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;path&apos;</span>)
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">rmSync</span>(<span class="hljs-params">dir</span>) </span>{
    <span class="hljs-keyword">try</span> {
        <span class="hljs-keyword">let</span> stat = fs.statSync(dir);
        <span class="hljs-keyword">if</span> (stat.isFile()) {
            fs.unlinkSync(dir);
        } <span class="hljs-keyword">else</span> {
            <span class="hljs-keyword">let</span> files=fs.readdirSync(dir);
            files
                .map(<span class="hljs-function"><span class="hljs-params">file</span> =&gt;</span> path.join(dir,file))
                .forEach(<span class="hljs-function"><span class="hljs-params">item</span>=&gt;</span>rmSync(item));
            fs.rmdirSync(dir);
        }
    } <span class="hljs-keyword">catch</span> (e) {
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;&#x5220;&#x9664;&#x5931;&#x8D25;!&apos;</span>);
    }
}
rmSync(path.join(__dirname,<span class="hljs-string">&apos;a&apos;</span>));
</code></pre>
<h3 id="t317.2 &#x5F02;&#x6B65;&#x5220;&#x9664;&#x975E;&#x7A7A;&#x76EE;&#x5F55;(Promise&#x7248;)">7.2 &#x5F02;&#x6B65;&#x5220;&#x9664;&#x975E;&#x7A7A;&#x76EE;&#x5F55;(Promise&#x7248;) <a href="#t317.2 &#x5F02;&#x6B65;&#x5220;&#x9664;&#x975E;&#x7A7A;&#x76EE;&#x5F55;(Promise&#x7248;)"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">rmPromise</span>(<span class="hljs-params">dir</span>) </span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function">(<span class="hljs-params">resolve,reject</span>) =&gt;</span> {
        fs.stat(dir,(err,stat) =&gt; {
            <span class="hljs-keyword">if</span> (err) <span class="hljs-keyword">return</span> reject(err);
            <span class="hljs-keyword">if</span> (stat.isDirectory()) {
                fs.readdir(dir,(err,files) =&gt; {
                    <span class="hljs-keyword">let</span> paths = files.map(<span class="hljs-function"><span class="hljs-params">file</span> =&gt;</span> path.join(dir,file));
                    <span class="hljs-keyword">let</span> promises = paths.map(<span class="hljs-function"><span class="hljs-params">p</span>=&gt;</span>rmPromise(p));
                    <span class="hljs-built_in">Promise</span>.all(promises).then(<span class="hljs-function">(<span class="hljs-params">(</span>) =&gt;</span> fs.rmdir(dir,resolve)));
                });
            } <span class="hljs-keyword">else</span> {
                fs.unlink(dir,resolve);
            }
        });
    });
}
rmPromise(path.join(__dirname,<span class="hljs-string">&apos;a&apos;</span>)).then(<span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;&#x5220;&#x9664;&#x6210;&#x529F;&apos;</span>);
})
</code></pre>
<h3 id="t327.3 &#x5F02;&#x6B65;&#x4E32;&#x884C;&#x5220;&#x9664;&#x76EE;&#x5F55;(&#x6DF1;&#x5EA6;&#x4F18;&#x5148;)">7.3 &#x5F02;&#x6B65;&#x4E32;&#x884C;&#x5220;&#x9664;&#x76EE;&#x5F55;(&#x6DF1;&#x5EA6;&#x4F18;&#x5148;) <a href="#t327.3 &#x5F02;&#x6B65;&#x4E32;&#x884C;&#x5220;&#x9664;&#x76EE;&#x5F55;(&#x6DF1;&#x5EA6;&#x4F18;&#x5148;)"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">rmAsyncSeries</span>(<span class="hljs-params">dir,callback</span>) </span>{
    setTimeout(<span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
        fs.stat(dir,(err,stat) =&gt; {
            <span class="hljs-keyword">if</span> (err) <span class="hljs-keyword">return</span> callback(err);
            <span class="hljs-keyword">if</span> (stat.isDirectory()) {
                fs.readdir(dir,(err,files) =&gt; {
                    <span class="hljs-keyword">let</span> paths = files.map(<span class="hljs-function"><span class="hljs-params">file</span> =&gt;</span> path.join(dir,file));
                    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">next</span>(<span class="hljs-params">index</span>) </span>{
                        <span class="hljs-keyword">if</span> (index&gt;=files.length) <span class="hljs-keyword">return</span> fs.rmdir(dir,callback);
                        <span class="hljs-keyword">let</span> current=paths[index];
                        rmAsyncSeries(current,()=&gt;next(index+<span class="hljs-number">1</span>));
                    }
                    next(<span class="hljs-number">0</span>);
                });
            } <span class="hljs-keyword">else</span> {
                fs.unlink(dir,callback);
            }
        })
    },<span class="hljs-number">1000</span>);
}

<span class="hljs-built_in">console</span>.time(<span class="hljs-string">&apos;cost&apos;</span>);
rmAsyncSeries(path.join(__dirname,<span class="hljs-string">&apos;a&apos;</span>),err =&gt; {
     <span class="hljs-built_in">console</span>.timeEnd(<span class="hljs-string">&apos;cost&apos;</span>);
})
</code></pre>
<h3 id="t337.4 &#x5F02;&#x6B65;&#x5E76;&#x884C;&#x5220;&#x9664;&#x76EE;&#x5F55;(&#x6DF1;&#x5EA6;&#x4F18;&#x5148;)">7.4 &#x5F02;&#x6B65;&#x5E76;&#x884C;&#x5220;&#x9664;&#x76EE;&#x5F55;(&#x6DF1;&#x5EA6;&#x4F18;&#x5148;) <a href="#t337.4 &#x5F02;&#x6B65;&#x5E76;&#x884C;&#x5220;&#x9664;&#x76EE;&#x5F55;(&#x6DF1;&#x5EA6;&#x4F18;&#x5148;)"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">rmAsyncParallel</span>(<span class="hljs-params">dir,callback</span>) </span>{
    setTimeout(<span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
        fs.stat(dir,(err,stat) =&gt; {
            <span class="hljs-keyword">if</span> (err) <span class="hljs-keyword">return</span> callback(err);
            <span class="hljs-keyword">if</span> (stat.isDirectory()) {
                fs.readdir(dir,(err,files) =&gt; {
                    <span class="hljs-keyword">let</span> paths=files.map(<span class="hljs-function"><span class="hljs-params">file</span> =&gt;</span> path.join(dir,file));
                    <span class="hljs-keyword">if</span> (paths.length&gt;<span class="hljs-number">0</span>) {
                        <span class="hljs-keyword">let</span> i=<span class="hljs-number">0</span>;
                        <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">done</span>(<span class="hljs-params"></span>) </span>{
                            <span class="hljs-keyword">if</span> (++i == paths.length) {
                                fs.rmdir(dir,callback);
                            }
                        }
                      paths.forEach(<span class="hljs-function"><span class="hljs-params">p</span>=&gt;</span>rmAsyncParallel(p,done));
                    } <span class="hljs-keyword">else</span> {
                        fs.rmdir(dir,callback);
                    }
                });
            } <span class="hljs-keyword">else</span> {
                fs.unlink(dir,callback);
            }
        })
    },<span class="hljs-number">1000</span>);
}
<span class="hljs-built_in">console</span>.time(<span class="hljs-string">&apos;cost&apos;</span>);
rmAsyncParallel(path.join(__dirname,<span class="hljs-string">&apos;a&apos;</span>),err =&gt; {
     <span class="hljs-built_in">console</span>.timeEnd(<span class="hljs-string">&apos;cost&apos;</span>);
})
</code></pre>
<h3 id="t347.5 &#x540C;&#x6B65;&#x5220;&#x9664;&#x76EE;&#x5F55;(&#x5E7F;&#x5EA6;&#x4F18;&#x5148;)">7.5 &#x540C;&#x6B65;&#x5220;&#x9664;&#x76EE;&#x5F55;(&#x5E7F;&#x5EA6;&#x4F18;&#x5148;) <a href="#t347.5 &#x540C;&#x6B65;&#x5220;&#x9664;&#x76EE;&#x5F55;(&#x5E7F;&#x5EA6;&#x4F18;&#x5148;)"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">rmSync</span>(<span class="hljs-params">dir</span>)</span>{
    <span class="hljs-keyword">let</span> arr=[dir];
    <span class="hljs-keyword">let</span> index=<span class="hljs-number">0</span>;
    <span class="hljs-keyword">while</span> (arr[index]) {
        <span class="hljs-keyword">let</span> current=arr[index++];
        <span class="hljs-keyword">let</span> stat=fs.statSync(current);
        <span class="hljs-keyword">if</span> (stat.isDirectory()) {
            <span class="hljs-keyword">let</span> dirs=fs.readdirSync(current);
            arr=[...arr,...dirs.map(<span class="hljs-function"><span class="hljs-params">d</span> =&gt;</span> path.join(current,d))];
        }
    }
    <span class="hljs-keyword">let</span> item;
    <span class="hljs-keyword">while</span> (<span class="hljs-literal">null</span> != (item = arr.pop())) {
        <span class="hljs-keyword">let</span> stat = fs.statSync(item);
        <span class="hljs-keyword">if</span> (stat.isDirectory()) {
            fs.rmdirSync(item);
        } <span class="hljs-keyword">else</span> {
            fs.unlinkSync(item);
        }
    }
}
</code></pre>
<h3 id="t357.6 &#x5F02;&#x6B65;&#x5220;&#x9664;&#x76EE;&#x5F55;(&#x5E7F;&#x5EA6;&#x4F18;&#x5148;)">7.6 &#x5F02;&#x6B65;&#x5220;&#x9664;&#x76EE;&#x5F55;(&#x5E7F;&#x5EA6;&#x4F18;&#x5148;) <a href="#t357.6 &#x5F02;&#x6B65;&#x5220;&#x9664;&#x76EE;&#x5F55;(&#x5E7F;&#x5EA6;&#x4F18;&#x5148;)"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">rmdirWideAsync</span>(<span class="hljs-params">dir,callback</span>)</span>{
    <span class="hljs-keyword">let</span> dirs=[dir];
    <span class="hljs-keyword">let</span> index=<span class="hljs-number">0</span>;
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">rmdir</span>(<span class="hljs-params"></span>) </span>{
        <span class="hljs-keyword">let</span> current = dirs.pop();
        <span class="hljs-keyword">if</span> (current) {
            fs.stat(current,(err,stat) =&gt; {
                <span class="hljs-keyword">if</span> (stat.isDirectory()) {
                    fs.rmdir(current,rmdir);
                } <span class="hljs-keyword">else</span> {
                    fs.unlink(current,rmdir);
                }
            });
        }
    }
    !<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">next</span>(<span class="hljs-params"></span>) </span>{
        <span class="hljs-keyword">let</span> current=dirs[index++];
        <span class="hljs-keyword">if</span> (current) {
            fs.stat(current,(err,stat) =&gt; {
                <span class="hljs-keyword">if</span> (err) callback(err);
                <span class="hljs-keyword">if</span> (stat.isDirectory()) {
                    fs.readdir(current,(err,files) =&gt; {
                        dirs=[...dirs,...files.map(<span class="hljs-function"><span class="hljs-params">item</span> =&gt;</span> path.join(current,item))];
                        next();
                    });
                } <span class="hljs-keyword">else</span> {
                    next();
                }
            });
        } <span class="hljs-keyword">else</span> {
            rmdir();
        }

    }();
}
</code></pre>
<h2 id="t368.  &#x904D;&#x5386;&#x7B97;&#x6CD5;">8.  &#x904D;&#x5386;&#x7B97;&#x6CD5; <a href="#t368.  &#x904D;&#x5386;&#x7B97;&#x6CD5;"> # </a></h2>
<ul>
<li>&#x76EE;&#x5F55;&#x662F;&#x4E00;&#x4E2A;&#x6811;&#x72B6;&#x7ED3;&#x6784;&#xFF0C;&#x5728;&#x904D;&#x5386;&#x65F6;&#x4E00;&#x822C;&#x4F7F;&#x7528;&#x6DF1;&#x5EA6;&#x4F18;&#x5148;+&#x5148;&#x5E8F;&#x904D;&#x5386;&#x7B97;&#x6CD5;</li>
<li>&#x6DF1;&#x5EA6;&#x4F18;&#x5148;&#xFF0C;&#x610F;&#x5473;&#x7740;&#x5230;&#x8FBE;&#x4E00;&#x4E2A;&#x8282;&#x70B9;&#x540E;&#xFF0C;&#x9996;&#x5148;&#x63A5;&#x7740;&#x904D;&#x5386;&#x5B50;&#x8282;&#x70B9;&#x800C;&#x4E0D;&#x662F;&#x90BB;&#x5C45;&#x8282;&#x70B9;</li>
<li>&#x5148;&#x5E8F;&#x904D;&#x5386;&#xFF0C;&#x610F;&#x5473;&#x7740;&#x9996;&#x6B21;&#x5230;&#x8FBE;&#x4E86;&#x67D0;&#x8282;&#x70B9;&#x5C31;&#x7B97;&#x904D;&#x5386;&#x5B8C;&#x6210;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x6700;&#x540E;&#x4E00;&#x6B21;&#x8FD4;&#x56DE;&#x67D0;&#x8282;&#x70B9;&#x624D;&#x7B97;&#x6570;</li>
<li>&#x56E0;&#x6B64;&#x4F7F;&#x7528;&#x8FD9;&#x79CD;&#x904D;&#x5386;&#x65B9;&#x5F0F;&#x65F6;&#xFF0C;&#x4E0B;&#x8FB9;&#x8FD9;&#x68F5;&#x6811;&#x7684;&#x904D;&#x5386;&#x987A;&#x5E8F;&#x662F;A &gt; B &gt; D &gt; E &gt; C &gt; F&#x3002;<pre><code class="lang-js">        A
       / \
      B   C
     / \   \
    D   E   F
</code></pre>
<h3 id="t378.1 &#x540C;&#x6B65;&#x6DF1;&#x5EA6;&#x4F18;&#x5148;+&#x5148;&#x5E8F;&#x904D;&#x5386;">8.1 &#x540C;&#x6B65;&#x6DF1;&#x5EA6;&#x4F18;&#x5148;+&#x5148;&#x5E8F;&#x904D;&#x5386; <a href="#t378.1 &#x540C;&#x6B65;&#x6DF1;&#x5EA6;&#x4F18;&#x5148;+&#x5148;&#x5E8F;&#x904D;&#x5386;"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">deepSync</span>(<span class="hljs-params">dir</span>)</span>{
  <span class="hljs-built_in">console</span>.log(dir);
  fs.readdirSync(dir).forEach(<span class="hljs-function"><span class="hljs-params">file</span>=&gt;</span>{
      <span class="hljs-keyword">let</span> child = path.join(dir,file);
      <span class="hljs-keyword">let</span> stat = fs.statSync(child);
      <span class="hljs-keyword">if</span>(stat.isDirectory()){
          deepSync(child);
      }<span class="hljs-keyword">else</span>{
          <span class="hljs-built_in">console</span>.log(child);
      }
  });
}
</code></pre>
<h3 id="t388.2 &#x5F02;&#x6B65;&#x6DF1;&#x5EA6;&#x4F18;&#x5148;+&#x5148;&#x5E8F;&#x904D;&#x5386;">8.2 &#x5F02;&#x6B65;&#x6DF1;&#x5EA6;&#x4F18;&#x5148;+&#x5148;&#x5E8F;&#x904D;&#x5386; <a href="#t388.2 &#x5F02;&#x6B65;&#x6DF1;&#x5EA6;&#x4F18;&#x5148;+&#x5148;&#x5E8F;&#x904D;&#x5386;"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">deep</span>(<span class="hljs-params">dir,callback</span>) </span>{
  <span class="hljs-built_in">console</span>.log(dir);
  fs.readdir(dir,(err,files)=&gt;{
      !<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">next</span>(<span class="hljs-params">index</span>)</span>{
          <span class="hljs-keyword">if</span>(index == files.length){
              <span class="hljs-keyword">return</span> callback();
          }
          <span class="hljs-keyword">let</span> child = path.join(dir,files[index]);
          fs.stat(child,(err,stat)=&gt;{
              <span class="hljs-keyword">if</span>(stat.isDirectory()){
                  deep(child,()=&gt;next(index+<span class="hljs-number">1</span>));
              }<span class="hljs-keyword">else</span>{
                  <span class="hljs-built_in">console</span>.log(child);
                  next(index+<span class="hljs-number">1</span>);
              }
          })
      }(<span class="hljs-number">0</span>)
  })
}
</code></pre>
<h3 id="t398.3 &#x540C;&#x6B65;&#x5E7F;&#x5EA6;&#x4F18;&#x5148;+&#x5148;&#x5E8F;&#x904D;&#x5386;">8.3 &#x540C;&#x6B65;&#x5E7F;&#x5EA6;&#x4F18;&#x5148;+&#x5148;&#x5E8F;&#x904D;&#x5386; <a href="#t398.3 &#x540C;&#x6B65;&#x5E7F;&#x5EA6;&#x4F18;&#x5148;+&#x5148;&#x5E8F;&#x904D;&#x5386;"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">wideSync</span>(<span class="hljs-params">dir</span>)</span>{
  <span class="hljs-keyword">let</span> dirs = [dir];
  <span class="hljs-keyword">while</span>(dirs.length&gt;<span class="hljs-number">0</span>){
      <span class="hljs-keyword">let</span> current = dirs.shift();
      <span class="hljs-built_in">console</span>.log(current);
      <span class="hljs-keyword">let</span> stat = fs.statSync(current);
      <span class="hljs-keyword">if</span>(stat.isDirectory()){
          <span class="hljs-keyword">let</span> files = fs.readdirSync(current);
          files.forEach(<span class="hljs-function"><span class="hljs-params">item</span>=&gt;</span>{
              dirs.push(path.join(current,item));
          });
      }
  }
}
</code></pre>
</li>
</ul>
<h3 id="t408.4 &#x5F02;&#x6B65;&#x5E7F;&#x5EA6;&#x4F18;&#x5148;+&#x5148;&#x5E8F;&#x904D;&#x5386;">8.4 &#x5F02;&#x6B65;&#x5E7F;&#x5EA6;&#x4F18;&#x5148;+&#x5148;&#x5E8F;&#x904D;&#x5386; <a href="#t408.4 &#x5F02;&#x6B65;&#x5E7F;&#x5EA6;&#x4F18;&#x5148;+&#x5148;&#x5E8F;&#x904D;&#x5386;"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-comment">// &#x5F02;&#x6B65;&#x5E7F;&#x5EA6;&#x904D;&#x5386;</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">wide</span>(<span class="hljs-params">dir, cb</span>) </span>{
    <span class="hljs-built_in">console</span>.log(dir);
    cb &amp;&amp; cb()
    fs.readdir(dir, (err, files) =&gt; {
        !<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">next</span>(<span class="hljs-params">i</span>)</span>{
            <span class="hljs-keyword">if</span>(i&gt;= files.length) <span class="hljs-keyword">return</span>;
            <span class="hljs-keyword">let</span> child = path.join(dir,files[i]);
            fs.stat(child,(err,stat)=&gt;{
                <span class="hljs-keyword">if</span>(stat.isDirectory()){
                    wide(child, () =&gt; next(i+<span class="hljs-number">1</span>));
                } <span class="hljs-keyword">else</span> {
                    <span class="hljs-built_in">console</span>.log(child);
                    next(i+<span class="hljs-number">1</span>);
                }
            })
        }(<span class="hljs-number">0</span>);
    })
}
wide(path.join(__dirname,<span class="hljs-string">&apos;a&apos;</span>));
</code></pre>
<h2 id="t418. path&#x6A21;&#x5757;">8. path&#x6A21;&#x5757; <a href="#t418. path&#x6A21;&#x5757;"> # </a></h2>
<p>path&#x662F;node&#x4E2D;&#x4E13;&#x95E8;&#x5904;&#x7406;&#x8DEF;&#x5F84;&#x7684;&#x4E00;&#x4E2A;&#x6838;&#x5FC3;&#x6A21;&#x5757;</p>
<ul>
<li>path.join
&#x5C06;&#x591A;&#x4E2A;&#x53C2;&#x6570;&#x503C;&#x5B57;&#x7B26;&#x4E32;&#x7ED3;&#x5408;&#x4E3A;&#x4E00;&#x4E2A;&#x8DEF;&#x5F84;&#x5B57;&#x7B26;&#x4E32;</li>
<li>path.basename
&#x83B7;&#x53D6;&#x4E00;&#x4E2A;&#x8DEF;&#x5F84;&#x4E2D;&#x7684;&#x6587;&#x4EF6;&#x540D;</li>
<li>path.extname
&#x83B7;&#x53D6;&#x4E00;&#x4E2A;&#x8DEF;&#x5F84;&#x4E2D;&#x7684;&#x6269;&#x5C55;&#x540D;</li>
<li>path.sep
&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x63D0;&#x5B9A;&#x7684;&#x6587;&#x4EF6;&#x5206;&#x9694;&#x7B26;</li>
<li>path.delimiter
&#x5C5E;&#x6027;&#x503C;&#x4E3A;&#x7CFB;&#x7EDF;&#x6307;&#x5B9A;&#x7684;&#x73AF;&#x5883;&#x53D8;&#x91CF;&#x8DEF;&#x5F84;&#x5206;&#x9694;&#x7B26;</li>
<li>path.normalize
&#x5C06;&#x975E;&#x6807;&#x51C6;&#x7684;&#x8DEF;&#x5F84;&#x5B57;&#x7B26;&#x4E32;&#x8F6C;&#x5316;&#x4E3A;&#x6807;&#x51C6;&#x8DEF;&#x5F84;&#x5B57;&#x7B26;&#x4E32;  &#x7279;&#x70B9;&#xFF1A;<ul>
<li>&#x53EF;&#x4EE5;&#x89E3;&#x6790; . &#x548C; ..</li>
<li>&#x591A;&#x4E2A;&#x6760;&#x53EF;&#x4EE5;&#x8F6C;&#x6362;&#x6210;&#x4E00;&#x4E2A;&#x6760;</li>
<li>&#x5728;windows&#x4E0B;&#x53CD;&#x6760;&#x4F1A;&#x8F6C;&#x5316;&#x6210;&#x6B63;&#x6760;</li>
<li>&#x5982;&#x7ED3;&#x5C3E;&#x4EE5;&#x6760;&#x7ED3;&#x5C3E;&#x7684;&#xFF0C;&#x5219;&#x4FDD;&#x7559;&#x659C;&#x6760;</li>
</ul>
</li>
<li>resolve<ul>
<li>&#x4EE5;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x6839;&#x76EE;&#x5F55;&#x4E3A;&#x8D77;&#x70B9;</li>
<li>&#x5982;&#x679C;&#x53C2;&#x6570;&#x662F;&#x666E;&#x901A;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x5219;&#x610F;&#x601D;&#x662F;&#x5F53;&#x524D;&#x76EE;&#x5F55;&#x7684;&#x4E0B;&#x7EA7;&#x76EE;&#x5F55;</li>
<li>&#x5982;&#x679C;&#x53C2;&#x6570;&#x662F;.. &#x56DE;&#x5230;&#x4E0A;&#x4E00;&#x7EA7;&#x76EE;&#x5F55;</li>
<li>&#x5982;&#x679C;&#x662F;/&#x5F00;&#x5934;&#x8868;&#x793A;&#x4E00;&#x4E2A;&#x7EDD;&#x5BF9;&#x7684;&#x6839;&#x8DEF;&#x5F84;</li>
</ul>
</li>
</ul>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> path = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;path&apos;</span>);
<span class="hljs-keyword">var</span> fs = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;fs&apos;</span>);
<span class="hljs-comment">/**
 * normalize &#x5C06;&#x975E;&#x6807;&#x51C6;&#x5316;&#x7684;&#x8DEF;&#x5F84;&#x8F6C;&#x5316;&#x6210;&#x6807;&#x51C6;&#x5316;&#x7684;&#x8DEF;&#x5F84;
 * 1.&#x89E3;&#x6790;. &#x548C; ..
 * 2.&#x591A;&#x4E2A;&#x659C;&#x6760;&#x4F1A;&#x8F6C;&#x6210;&#x4E00;&#x4E2A;&#x659C;&#x6760;
 * 3.window&#x4E0B;&#x7684;&#x659C;&#x6760;&#x4F1A;&#x8F6C;&#x6210;&#x6B63;&#x659C;&#x6760;
 * 4.&#x5982;&#x679C;&#x4EE5;&#x659C;&#x6760;&#x4F1A;&#x4FDD;&#x7559;
 **/</span>

<span class="hljs-built_in">console</span>.log(path.normalize(<span class="hljs-string">&apos;./a////b//..\\c//e//..//&apos;</span>));
<span class="hljs-comment">//  \a\c\</span>

<span class="hljs-comment">//&#x591A;&#x4E2A;&#x53C2;&#x6570;&#x5B57;&#x7B26;&#x4E32;&#x5408;&#x5E76;&#x6210;&#x4E00;&#x4E2A;&#x8DEF;&#x5F84; &#x5B57;&#x7B26;&#x4E32;</span>
<span class="hljs-built_in">console</span>.log(path.join(__dirname,<span class="hljs-string">&apos;a&apos;</span>,<span class="hljs-string">&apos;b&apos;</span>));

<span class="hljs-comment">/**
 * resolve
 * &#x4EE5;&#x5C31;&#x7528;&#x7A0B;&#x5E8F;&#x4E3A;&#x6839;&#x76EE;&#x5F55;&#xFF0C;&#x505A;&#x4E3A;&#x8D77;&#x70B9;&#xFF0C;&#x6839;&#x636E;&#x53C2;&#x6570;&#x89E3;&#x6790;&#x51FA;&#x4E00;&#x4E2A;&#x7EDD;&#x5BF9;&#x8DEF;&#x5F84;
 *  1.&#x4EE5;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x4E3A;&#x6839;&#x8D77;&#x70B9;
 *  2... .
 *  3. &#x666E;&#x901A; &#x5B57;&#x7B26;&#x4E32;&#x4EE3;&#x8868;&#x5B50;&#x76EE;&#x5F55;
 *  4. /&#x4EE3;&#x8868;&#x7EDD;&#x5730;&#x8DEF;&#x5F84;&#x6839;&#x76EE;&#x5F55;
 */</span>
<span class="hljs-built_in">console</span>.log(path.resolve());<span class="hljs-comment">//&#x7A7A;&#x4EE3;&#x8868;&#x5F53;&#x524D;&#x7684;&#x76EE;&#x5F55; &#x8DEF;&#x5F84;</span>
<span class="hljs-built_in">console</span>.log(path.resolve(<span class="hljs-string">&apos;a&apos;</span>,<span class="hljs-string">&apos;/c&apos;</span>));<span class="hljs-comment">// /a/b</span>
<span class="hljs-comment">// d:\c</span>
<span class="hljs-comment">//&#x53EF;&#x4EE5;&#x83B7;&#x53D6;&#x4E24;&#x4E2A;&#x8DEF;&#x5F84;&#x4E4B;&#x95F4;&#x7684;&#x76F8;&#x5BF9;&#x5173;&#x7CFB;</span>
<span class="hljs-built_in">console</span>.log(path.relative(__dirname,<span class="hljs-string">&apos;/a&apos;</span>));
<span class="hljs-comment">// a</span>
<span class="hljs-comment">//&#x8FD4;&#x56DE;&#x6307;&#x5B9A;&#x8DEF;&#x5F84;&#x7684;&#x6240;&#x5728;&#x76EE;&#x5F55;</span>
<span class="hljs-built_in">console</span>.log(path.dirname(__filename)); <span class="hljs-comment">// 9.path</span>
<span class="hljs-built_in">console</span>.log(path.dirname(<span class="hljs-string">&apos;./1.path.js&apos;</span>));<span class="hljs-comment">//  9.path</span>
<span class="hljs-comment">//basename &#x83B7;&#x53D6;&#x8DEF;&#x5F84;&#x4E2D;&#x7684;&#x6587;&#x4EF6;&#x540D;</span>
<span class="hljs-built_in">console</span>.log(path.basename(__filename));
<span class="hljs-built_in">console</span>.log(path.basename(__filename,<span class="hljs-string">&apos;.js&apos;</span>));
<span class="hljs-built_in">console</span>.log(path.extname(__filename));

<span class="hljs-built_in">console</span>.log(path.sep);<span class="hljs-comment">//&#x6587;&#x4EF6;&#x5206;&#x9694;&#x7B26; window \ linux /</span>
<span class="hljs-built_in">console</span>.log(path.win32.sep);
<span class="hljs-built_in">console</span>.log(path.posix.sep);
<span class="hljs-built_in">console</span>.log(path.delimiter);<span class="hljs-comment">//&#x8DEF;&#x5F84; &#x5206;&#x9694;&#x7B26; window ; linux :</span>
</code></pre>
<h2 id="t429. flags">9. flags <a href="#t429. flags"> # </a></h2>
<table>
<thead>
<tr>
<th style="text-align:left">&#x7B26;&#x53F7;</th>
<th style="text-align:left">&#x542B;&#x4E49;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">r</td>
<td style="text-align:left">&#x8BFB;&#x6587;&#x4EF6;&#xFF0C;&#x6587;&#x4EF6;&#x4E0D;&#x5B58;&#x5728;&#x62A5;&#x9519;</td>
</tr>
<tr>
<td style="text-align:left">r+</td>
<td style="text-align:left">&#x8BFB;&#x53D6;&#x5E76;&#x5199;&#x5165;&#xFF0C;&#x6587;&#x4EF6;&#x4E0D;&#x5B58;&#x5728;&#x62A5;&#x9519;</td>
</tr>
<tr>
<td style="text-align:left">rs</td>
<td style="text-align:left">&#x540C;&#x6B65;&#x8BFB;&#x53D6;&#x6587;&#x4EF6;&#x5E76;&#x5FFD;&#x7565;&#x7F13;&#x5B58;</td>
</tr>
<tr>
<td style="text-align:left">w</td>
<td style="text-align:left">&#x5199;&#x5165;&#x6587;&#x4EF6;&#xFF0C;&#x4E0D;&#x5B58;&#x5728;&#x5219;&#x521B;&#x5EFA;&#xFF0C;&#x5B58;&#x5728;&#x5219;&#x6E05;&#x7A7A;</td>
</tr>
<tr>
<td style="text-align:left">wx</td>
<td style="text-align:left">&#x6392;&#x5B83;&#x5199;&#x5165;&#x6587;&#x4EF6;</td>
</tr>
<tr>
<td style="text-align:left">w+</td>
<td style="text-align:left">&#x8BFB;&#x53D6;&#x5E76;&#x5199;&#x5165;&#x6587;&#x4EF6;&#xFF0C;&#x4E0D;&#x5B58;&#x5728;&#x5219;&#x521B;&#x5EFA;&#xFF0C;&#x5B58;&#x5728;&#x5219;&#x6E05;&#x7A7A;</td>
</tr>
<tr>
<td style="text-align:left">wx+</td>
<td style="text-align:left">&#x548C;w+&#x7C7B;&#x4F3C;&#xFF0C;&#x6392;&#x4ED6;&#x65B9;&#x5F0F;&#x6253;&#x5F00;</td>
</tr>
<tr>
<td style="text-align:left">a</td>
<td style="text-align:left">&#x8FFD;&#x52A0;&#x5199;&#x5165;</td>
</tr>
<tr>
<td style="text-align:left">ax</td>
<td style="text-align:left">&#x4E0E;a&#x7C7B;&#x4F3C;&#xFF0C;&#x6392;&#x4ED6;&#x65B9;&#x5F0F;&#x5199;&#x5165;</td>
</tr>
<tr>
<td style="text-align:left">a+</td>
<td style="text-align:left">&#x8BFB;&#x53D6;&#x5E76;&#x8FFD;&#x52A0;&#x5199;&#x5165;&#xFF0C;&#x4E0D;&#x5B58;&#x5728;&#x5219;&#x521B;&#x5EFA;</td>
</tr>
<tr>
<td style="text-align:left">ax+</td>
<td style="text-align:left">&#x4F5C;&#x7528;&#x4E0E;a+&#x7C7B;&#x4F3C;&#xFF0C;&#x4F46;&#x662F;&#x4EE5;&#x6392;&#x4ED6;&#x65B9;&#x5F0F;&#x6253;&#x5F00;&#x6587;&#x4EF6;</td>
</tr>
</tbody>
</table>
<h2 id="t4310. &#x52A9;&#x8BB0;">10. &#x52A9;&#x8BB0; <a href="#t4310. &#x52A9;&#x8BB0;"> # </a></h2>
<ul>
<li>r &#x8BFB;&#x53D6;</li>
<li>w &#x5199;&#x5165;</li>
<li>s &#x540C;&#x6B65;</li>
<li>+ &#x589E;&#x52A0;&#x76F8;&#x53CD;&#x64CD;&#x4F5C;</li>
<li>x &#x6392;&#x4ED6;&#x65B9;&#x5F0F;</li>
<li>r+ w+&#x7684;&#x533A;&#x522B;?<ul>
<li>&#x5F53;&#x6587;&#x4EF6;&#x4E0D;&#x5B58;&#x5728;&#x65F6;&#xFF0C;r+&#x4E0D;&#x4F1A;&#x521B;&#x5EFA;&#xFF0C;&#x800C;&#x4F1A;&#x5BFC;&#x81F4;&#x8C03;&#x7528;&#x5931;&#x8D25;&#xFF0C;&#x4F46;w+&#x4F1A;&#x521B;&#x5EFA;&#x3002;</li>
<li>&#x5982;&#x679C;&#x6587;&#x4EF6;&#x5B58;&#x5728;&#xFF0C;r+&#x4E0D;&#x4F1A;&#x81EA;&#x52A8;&#x6E05;&#x7A7A;&#x6587;&#x4EF6;&#xFF0C;&#x4F46;w+&#x4F1A;&#x81EA;&#x52A8;&#x628A;&#x5DF2;&#x6709;&#x6587;&#x4EF6;&#x7684;&#x5185;&#x5BB9;&#x6E05;&#x7A7A;&#x3002;</li>
</ul>
</li>
</ul>
<h2 id="t4411. linux&#x6743;&#x9650;">11. linux&#x6743;&#x9650; <a href="#t4411. linux&#x6743;&#x9650;"> # </a></h2>
<table>
<thead>
<tr>
<th style="text-align:left">&#x6587;&#x4EF6;&#x7C7B;&#x578B;&#x4E0E;&#x6743;&#x9650;</th>
<th style="text-align:left">&#x94FE;&#x63A5;&#x5360;&#x7528;&#x7684;&#x8282;&#x70B9;(i-node)</th>
<th style="text-align:left">&#x6587;&#x4EF6;&#x6240;&#x6709;&#x8005;</th>
<th style="text-align:left">&#x6587;&#x4EF6;&#x6240;&#x6709;&#x8005;&#x7684;&#x7528;&#x6237;&#x7EC4;</th>
<th style="text-align:left">&#x6587;&#x4EF6;&#x5927;&#x5C0F;</th>
<th style="text-align:left">&#x6587;&#x4EF6;&#x7684;&#x521B;&#x5EFA;&#x65F6;&#x95F4;</th>
<th style="text-align:left">&#x6700;&#x8FD1;&#x4FEE;&#x6539;&#x65F6;&#x95F4;</th>
<th style="text-align:left">&#x6587;&#x4EF6;&#x540D;&#x79F0;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"></td>
</tr>
</tbody>
</table>
<p><img src="http://img.zhufengpeixun.cn/authorigy.jpg" alt="&#x6743;&#x9650;"></p>

        <div class="copyright">Powered by <a href="https://github.com/jaywcjlove/idoc" target="_blank">idoc</a>. Dependence <a href="https://nodejs.org">Node.js</a> run.</div>
    </div>
    
</div>

<script src="https://cdn.bootcss.com/jquery/3.0.0/jquery.js"></script>
<script>
$('.warpper .page-toc ul ul li a').on('click',function(){
  $('.warpper .page-toc ul ul li a').removeClass('my-active')
  $(this).addClass('my-active')
})
  // if (!$('.understand-me').length) {
  //   var bar = $(window).height() - $('.navbar ').height() - $('.page-toc').position().top;
  //   var count = bar / 26 / 2;
  //   var barHeight = $('.page-toc').outerHeight();
  //   $('.page-toc li').eq(0).children('a').addClass('red');
  //   var arr = [];
  //   $("h1,h2,h3,h4,h5,h6").each(function () {
  //     arr.push($(this).position().top);
  //   });
  //   var timer
  //   function dark() {
  //     clearTimeout(timer)
  //      timer = setTimeout(function () {
  //      var top = Math.abs($('.page-toc > ul').position().top);
  //      var cur = $('.content').scrollTop();
  //      for (var i = arr.length; i >= 0; i--) {
  //        if (arr[i] <= cur) {
  //          break;
  //        }
  //      }
  //      if (i === -1) {
  //        i = 0;
  //      }
  //      $('.page-toc li a').removeClass('red');
  //      $('.page-toc li').eq(i).children('a').addClass('red');
  //      let height = $('.page-toc li').eq(i).position().top-$('.page-toc').height(); // 如果当前的offset出去了 回到中间可好？
  //      $('.page-toc').scrollTop(height+$('.page-toc').height()/2);
  //    },200)
  //   }

  //   $('.content').on('scroll', dark);
  // }
</script>
<style>

    /* ::-webkit-scrollbar{width:14px;}
    ::-webkit-scrollbar-track{background-color:transparent;}
    ::-webkit-scrollbar-thumb{background-color:transparent;}
    ::-webkit-scrollbar-thumb:hover {background-color:transparent}
    ::-webkit-scrollbar-thumb:active {background-color:transparent} */

    .page-toc > ul .red {
        background: #f3f3f3;
        z-index: 1;
        border-left: 3px solid #009a61;
        -webkit-transition: all .2s ease;
        transition: all .2s ease;
        color: #000
    }





</style>
</body>
</html>
